package dashboard;

import java.util.ArrayList;
import java.util.List;


public class ChangeSettingsController{

	private User user;

	public  ChangeSettingsController()
	{
		user = new User();
	}

	public List<String> setInfo( String password, String cPassword, String email, String firstName, String name, String[] courses, String number, String role, int treshold)
	{
		List<String> exception = new ArrayList<String>();
		
		user.setFirstName(firstName);
		
		user.setName(name);
		
		user.setRole(role);

		user.setNumber(number);
		
		if(number != null && !number.startsWith("r") && !number.startsWith("u") || number.length() != 8 )
			exception.add("Student/tutor number should start with r or u and should be 8 chars long");
		
		if(!email.equals(user.getEmail())){	
			
		user.setEmail(email);

		if(!email.contains("@") || email.split("@")[0].length()<5 || !email.contains("."))
			exception.add("E-mail is not valid!");
		if( UserRegistry.getInstance().emailInUse(email))
			exception.add("E-mail is in use");
		}
		
		user.setTreshold(treshold);
		
		if(treshold > 90 || treshold < 10) exception.add("Treshold must be a value between 10 and 90");
		user.setPassword(password);

		if(password.length()<5)		exception.add("Password too short!");
		if(password.length()>20)	exception.add("Password too long!");
		if(!password.equals(cPassword)) exception.add("Passwords don't match");
		if(role.equals("student"))
			if(courses == null) exception.add("Select Courses please");
		return exception;
	}
	public void setUser(User user)
	{
		this.user = user;
	}
	public User getUser()
	{
		return user;
	}
	public void saveUser()
	{
		UserRegistry.getInstance().addUser(user);
		user = new User();
	}

}
